|
In the C++ programming language, a reference is a simple reference datatype that is less powerful but safer than the pointer type inherited from C. The name ''C++ reference'' may cause confusion, as in computer science a reference is a general concept datatype, with ''pointers'' and ''C++ references'' being specific reference datatype implementations. The definition of a reference in C++ is such that it does not need to exist. It can be implemented as a new name for an existing object (similar to rename keyword in Ada). == Syntax and terminology == The declaration of the form: where is a type and is an identifier whose type is reference to .Examples: int A = 5; extern int& rB; Here, rA and rB are of type "reference to int "int& foo (); foo() is a function that returns a "reference to int "void bar (int& rP); bar() is a function with a reference parameter, which is a "reference to int "class MyClass ; MyClass is a class with a member which is reference to int int funcX() ; int (&xFunc)() = funcX; funcX() is a function that returns a (non-reference type) int and xFunc() is an ''alias'' for funcX const int& ref = 65; const int& ref is a constant reference pointing to a piece of storage having value 65.Types which are of kind "reference to " are sometimes called reference types. Identifiers which are of reference type are called reference variables. To call them ''variable'', however, is in fact a misnomer, as we will see.抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Reference (C++)」の詳細全文を読む スポンサード リンク
|